package arrayListExercises.saveStudentList;

import java.util.ArrayList;

/**
 * @author: bamboo_shoot
 * @date: 20/2/5 14:28
 * @description: 需求：使用数组存储3个学生对象，然后遍历并输出。
 */
public class TraversalStudent {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<Student>();
        Student s1 = new Student("lanlan", "18");
        Student s2 = new Student("jianjian", "29");
        Student s3 = new Student("wenwen",  "49");
        students.add(s1);
        students.add(s2);
        students.add(s3);
        String age = students.get(2).getAge();
        String name = students.get(1).getName();
        System.out.println(name + "--" + age);
        Student remove = students.remove(0);
        traversal(students);
        System.out.println(remove.getName()+"--"+remove.getAge());
    }

    private static void traversal(ArrayList<Student> students) {
        for (Student student : students) {
            System.out.print(student.getName() + "--" + student.getAge() + ",");
        }
    }
}
